<?php
namespace app\member\controller;
class Social extends Common{
    function __construct(){
        parent::__construct();
        $navs=config("navs.1.children");
        $this->assign('_nav',json_encode($navs,JSON_UNESCAPED_UNICODE));
    }
    function index($soft_id=0){
        $user=$this->user;
        $params=input('');
        $soft=model('software')->read(['id'=>$soft_id],'name');
        $this->assign('soft',$soft);
        $list=model($this->table)->readAll(['member_id'=>$user['id'],'soft_id'=>$soft_id],true);
        $list->appends($params);
        $this->assign('list',$list);
        $this->assign('params',$params);
        return view();
    }
    function del($id=0,$soft_id=0){
        $ids=input('ids/a',[]);
        if(($id<=0&&empty($ids))||$soft_id<=0){
            $this->error('数据不存在!');
        }
        $member_id=$this->user['id'];
        $where=[
            'member_id'=>$member_id,
            'soft_id'=>$soft_id,
            'id'=>$id
        ];
        if(count($ids)){
            $where['id']=['id','in',$ids];
        }
        $del=model($this->table)->del($where);
        if(!$del){
            $this->error('系统繁忙删除失败');
        }
        $this->success('删除成功!');

    }
    // 无效
    function logs($ids=[]){
        $list=model('social')->logs(['id'=>['id','in',$ids]]);
        $this->success('','',$list);
    }
    /**
     * 获取好友数据
     * @param  array  $ids ['soft_id_social_id']
     * @return [type]      [description]
     */
    function read($ids=[]){
        if(request()->isAjax()||request()->isPost()){
            $options=[
                'field'=>'id,soft_id,number,name,head_img',
                'with'=>['software','software.device'],
            ];
            $map='';
            foreach ($ids as $k => $v) {
                $arr=explode('_', $v);
                if(strlen($map)){
                    $map.=' or ';
                }
                $map.=" (id =".$arr[1]." and soft_id=".$arr[0].") ";
            }
            $list=model($this->table)->readAll($map,0,$options);
            $this->success('','',$list);
        }
    }
}
